package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Letter;
import cn.wolfcode.trip.base.domain.TravelComment;
import cn.wolfcode.trip.base.mapper.TravelCommentMapper;
import cn.wolfcode.trip.base.query.LikeQueryObject;
import cn.wolfcode.trip.base.service.ITravelCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TravelCommentServiceImpl implements ITravelCommentService {

    @Autowired
    private TravelCommentMapper travelCommentMapper;


    @Override
    public List<TravelComment> queryByTravelId(Long travelId) {
        List<TravelComment> list = travelCommentMapper.selectCommentsByTravelId(travelId);
        return list;
    }

    @Override
    public void save(TravelComment travelComment) {
        travelCommentMapper.insert(travelComment);
    }

    @Override
    public void updateState(Long authorId) {
         travelCommentMapper.updateState(authorId);
    }

    @Override
    public TravelComment getByTravelCommentId(Long travelCommentId) {
        return travelCommentMapper.selectByPrimaryKey(travelCommentId);

    }

    @Override
    public Integer getReplyCount(Long travelCommentId) {
        return travelCommentMapper.selectReplyCount(travelCommentId);
    }

    @Override
    public void updateReplyCount(int replyCount, Long travelCommentId) {
        travelCommentMapper.updateReplyCount(replyCount,travelCommentId);
    }

    @Override
    public Integer countComment(LikeQueryObject qo) {
        //判断是否 查出 为null
        Integer countUnReadSystemMessages = travelCommentMapper.countComment(qo);
        if(countUnReadSystemMessages == null){
            return 0;
        }else {
            return  countUnReadSystemMessages;
        }
    }

    @Override
    public Integer countOthersComment(LikeQueryObject qo) {
        //判断是否 查出 为null
        Integer countUnReadSystemMessages = travelCommentMapper.countOthersComment(qo);
        if(countUnReadSystemMessages == null){
            return 0;
        }else {
            return  countUnReadSystemMessages;
        }
    }

    @Override
    public Object maxComment(LikeQueryObject qo) {
        return travelCommentMapper.maxComment(qo);
    }
}
